<?php
$yhendus=new mysqli("localhost", "if13", "ifikad", "if13_ooloma");
if(isSet($_REQUEST["uusleht"])){
$kask=$yhendus->prepare("INSERT INTO loetelu (nimi, sugu, vanus) VALUES (?, ?, ?)");
$kask->bind_param("ssi", $_REQUEST["nimi"], $_REQUEST["sugu"], $_REQUEST["vanus"] );
$kask->execute();
header("Location: $_SERVER[PHP_SELF]");
$yhendus->close();
exit();
}
if(isSet($_REQUEST["kustutusid"])){
$kask=$yhendus->prepare("DELETE FROM loetelu WHERE id=?");
$kask->bind_param("i", $_REQUEST["kustutusid"]);
$kask->execute();
}
?>
<!doctype html>
<html>
<head>
<title>registreerimine</title>
<style type="text/css">
#menyykiht{
float: left;
padding-right: 30px;
}
#sisukiht{
float:left;
}
#jalusekiht{
clear: left;
}
</style>
</head>
<body>
<div id="menyykiht">
<h2>Registeerimisvorm</h2>
<ul>
<?php
$kask=$yhendus->prepare("SELECT id, nimi, sugu, vanus FROM loetelu");
echo $yhendus->error;
$kask->bind_result($id, $nimi, $sugu, $vanus);
$kask->execute();
while($kask->fetch()){
echo "<li><a href='?id=$id'>".
htmlspecialchars($nimi)."</a></li>";
}
?>
</ul>
<a href='?lisamine=jah'>Lisa ...</a>
</div>
<div id="sisukiht">
<?php
if(isSet($_REQUEST["id"])){
$kask=$yhendus->prepare("SELECT id, nimi, sugu, vanus FROM loetelu
WHERE id=?");
$kask->bind_param("i", $_REQUEST["id"]);
$kask->bind_result($id, $nimi, $sugu, $vanus);
$kask->execute();
if($kask->fetch()){
echo "<h2>".htmlspecialchars($nimi)."</h2>";
echo htmlspecialchars($sugu);
echo "<br /+>";
echo htmlspecialchars($vanus);
echo "<br /+><a href='?kustutusid=$id'>kustuta</a>";
} else {
echo "Vigased andmed.";
}
}
if(isSet($_REQUEST["lisamine"])){
?>
<form action='?'>
<input type="hidden" name="uusleht" value="jah" />
<h2>Uue vormi lisamine</h2>
<dl>
<dt>nimi:</dt>
<dd>
<input type="text" name="nimi" />
</dd>
<dt>sugu:</dt>
<dd>
<input type="text" name="sugu" />
</dd>
<dt>vanus:</dt>
<dd>
<input type="text" name="vanus" />
</dl>
<input type="submit" value="sisesta">
</form>
<?php
}
?>
</div>
<div id="jalusekiht">
Lehe tegid Sten,Mati,Hets,Freddy
</div>
</body>
</html>
<?php
$yhendus->close();
?>